package 笔试.网易.面试;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/9/5-15:58
 * @version:1.0
 * @function:
 */
public class Main02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String ox = scanner.next();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < ox.length(); i++) {
            if (ox.charAt(i)=='X') {
                list.add(i);
            }
        }
        int m = scanner.nextInt();
        String[] res = new String[m];
        for (int i = 0; i < m; i++) {
            String str = scanner.next();
            res[i] = fun(list,str);
        }
        for (int i = 0; i < res.length; i++) {
            System.out.println(res[i]);
        }
    }

    private static String fun(ArrayList<Integer> list, String str) {
        for (int i = 0; i < list.size(); i++) {
            if (str.charAt(list.get(i))=='1') {
                return "NO";
            }
        }
        return "YES";
    }
}
